package com.gl.marina;
import org.junit.*;

import java.util.*;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
public class testListForTest {
    ListForTest lt=new ListForTest();
    ListForTest mockedList=mock(ListForTest.class);
    List <String> list =new ArrayList<String>() ;
    @Before
    public void setUp(){
        list.add(0, "zero");
        list.add(1, "one");
        list.add(2, "two");
        list.add(3, "three");
        list.add(4, "four");
    }
    @Test
    public void testInsertByIndex() {
        doThrow(new IndexOutOfBoundsException()).when(mockedList).insertByIndex(10, "ten",list);
 }
    @Test
    public void testRemoveByIndex() {
        assertEquals("two", lt.removeByIndex(2,list));
    }
    @Test
    public void testIsExist() throws Exception {
       assertTrue(lt.isExist("two",list));
       assertFalse(lt.isExist("five",list));
    }
    @Test
    public void testIteratorArrayList() throws Exception {
        List<String> first_AL=new ArrayList<String>() ;
        Iterator first_it =first_AL.iterator();
        List<String> second_AL=new ArrayList<String>() ;
        second_AL.add("second_AL");
        Iterator second_it =second_AL.iterator();
        assertTrue(lt.IteratorArrayList(list));
        assertFalse(first_it.hasNext());
        assertTrue(second_it.hasNext());
    }
     @Test(expected = IndexOutOfBoundsException.class)
     public void checkIOOBEException (){
         List <String> myAL=new ArrayList<String>() ;
         myAL.get(7);
     }
     @Test(expected = NoSuchElementException.class)
     public void checkNSEException (){
        List<String> myAL=new ArrayList<String>() ;
        myAL.add(0,"zero");
        myAL.add(1,"one");
        Iterator it = myAL.iterator();
        for (int i=1;i<10;i++){
            String element= (String) it.next();
        }
    }
     @Test
    public void testRemovingAll() {
        mockedList.removingAll(list);
        verify(mockedList).removingAll(list);
    }
}

